﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="FisheryPlatform.Web.Admin.Posts.Index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register TagName="Style" TagPrefix="Menu" Src="~/Modules/Menu/StyleMenu.ascx" %>
<%@ Register TagName="Left" TagPrefix="Menu" Src="~/Modules/Menu/LeftMenu.ascx" %>
<%@ Register TagName="Header" TagPrefix="Menu" Src="~/Modules/Menu/HeaderMenu.ascx" %>
<%@ Register TagName="Footer" TagPrefix="Menu" Src="~/Modules/Menu/FooterMenu.ascx" %>
<%@ Register TagName="PageBar" TagPrefix="ucPB" Src="~/Modules/PageBar.ascx" %>
<%@ Import Namespace="FisheryPlatform.Entity" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Menu:Style runat="server" ID="menuStyle" Title="Hi"></Menu:Style>
</head>
<body>
    <div class="wrapper">
        <Menu:Header runat="server" ID="menuHeader" />
        <div class="content">
            <Menu:Left runat="server" ID="menu_Left" />
            <div class="right">
                <div class="top">
                    文章管理>>所有文章</div>
                <div class="bottom">
                    <form id="form1" runat="server">
                    <div class="menu_nav">
                        <ul>
                            <li class=""><a href="Index.aspx?status=-1">全部 <span>(<%=GetTotalAmount()%>)</span></a>|</li>
                            <%if (AmountList.ContainsKey((int)PostStatusEnum.Publish))
                              {%>
                            <li class=""><a href="Index.aspx?status=1">已发布<span>(<%=AmountList[(int)PostStatusEnum.Publish]%>)</span></a>|</li>
                            <%} %>
                            <%if (HotPostHomeList.Count > 0)
                              {%>
                            <li class=""><a href="Index.aspx?status=1&show_hot=<%=string.Join(",", HotPostHomeList.ToArray())%>">
                                首页推荐<span>(<%=HotPostHomeList.Count%>)</span></a>|</li>
                            <%} %>
                            <%if (HotPostTopList.Count > 0)
                              {%>
                            <li class=""><a href="Index.aspx?status=1&show_hot=<%=string.Join(",", HotPostTopList.ToArray())%>">
                                列表置顶<span>(<%=HotPostTopList.Count%>)</span></a>|</li>
                            <%} %>
                            <%if (AmountList.ContainsKey((int)PostStatusEnum.Draft))
                              {%>
                            <li class=""><a href="Index.aspx?status=3">草稿 <span>(<%=AmountList[(int)PostStatusEnum.Draft]%>)</span></a>|</li>
                            <%} %>
                            <%if (AmountList.ContainsKey((int)PostStatusEnum.Private))
                              {%>
                            <li class=""><a href="Index.aspx?status=4">私密 <span>(<%=AmountList[(int)PostStatusEnum.Private]%>)</span></a>|</li>
                            <%} %>
                            <%if (AmountList.ContainsKey((int)PostStatusEnum.Trash))
                              {%>
                            <li class=""><a href="Index.aspx?status=5">回收站 <span>(<%=AmountList[(int)PostStatusEnum.Trash]%>)</span></a></li>
                            <%} %>
                        </ul>
                    </div>
                    <div class="clear">
                    </div>
                    <div class="list_title">
                        <% if (Request.QueryString["status"] == ((int)PostStatusEnum.Trash).ToString())
                           {%>
                        <a onclick="movePostToPublish()" href="javascript:;">恢复</a>
                        <%}
                           else
                           { %>
                        <a onclick="movePostToTrash()" href="javascript:;">移至回收站</a><%} %>&nbsp;&nbsp;
                        <select id="sel_Cate">
                            <option value="-1">所有分类</option>
                            <% foreach (var item in FisheryPlatform.Bussiness.Term.TermManager.GetPostCateList())
                               {%>
                            <option value="<%=item.id %>" <%=item.id.ToString()==Request.QueryString["cate"]?" selected":"" %>>
                                <%for (var i = 0; i < item.level; i++)
                                  { %>&nbsp;<%} %>
                                <%=item.name%></option>
                            <%} %>
                        </select>
                        <input type="button" value="筛选" onclick="filterPostCate()" />
                    </div>
                    <table class="list" cellspacing="0" cellpadding="0" id="tbl_List">
                        <tr>
                            <th valign="middle" align="center" style="width: 3%;">
                                <input type="checkbox" name="chk_All" id="chk_TopAll" onclick="CheckBox.selected('tbl_List',this.checked,'chk_All')" />
                            </th>
                            <th style="width: 15%;">
                                标题
                            </th>
                            <th style="width: 10%;">
                                作者
                            </th>
                            <th style="width: 16%;">
                                分类
                            </th>
                            <th style="width: 16%;">
                                标签
                            </th>
                            <th style="width: 12%;">
                                更新时间
                            </th>
                            <th style="width: 12%;">
                                创建时间
                            </th>
                            <th style="width: 16%;">
                                热门设置
                            </th>
                        </tr>
                        <% foreach (var post in PostList)
                           { %>
                        <tr>
                            <td valign="middle" align="center">
                                <input type="checkbox" onclick="CheckBox.isAll('tbl_List',['chk_TopAll'])" value="<%=post.PostId %>" />
                            </td>
                            <td>
                                <a href="New.aspx?postId=<%=post.PostId %>">
                                    <%= HttpUtility.HtmlEncode(post.Title) %></a>
                            </td>
                            <td>
                                <%=HttpUtility.HtmlEncode(UserName(post.AuthorId))%>
                            </td>
                            <td>
                                <%=GetCateNames(post.PostId)%>
                            </td>
                            <td>
                                <%=GetTagNames(post.PostId)%>
                            </td>
                            <td>
                                <%=post.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss") %>
                            </td>
                            <td>
                                <%=post.PostDate.ToString("yyyy-MM-dd HH:mm:ss") %>
                            </td>
                            <td>
                                首页推荐&nbsp;<a href="javascript:;" onclick="hotSettings(<%=post.PostId %>,'<%=OptionNameConstants.Posts_Home %>',<%=HotPostHomeList.Contains(post.PostId.ToString())?"0":"1" %>,this)"><%=HotPostHomeList.Contains(post.PostId.ToString())?"取消":"设置" %></a><br />
                                列表置顶&nbsp;<a href="javascript:;" onclick="hotSettings(<%=post.PostId %>,'<%=OptionNameConstants.Posts_Top %>',<%=HotPostTopList.Contains(post.PostId.ToString())?"0":"1" %>,this)"><%=HotPostTopList.Contains(post.PostId.ToString())?"取消":"设置" %></a>
                            </td>
                        </tr>
                        <%} %>
                    </table>
                    <div>
                        <ucPB:PageBar runat="server" ID="pb_PageBar" />
                    </div>
                    </form>
                </div>
            </div>
        </div>
        <Menu:Footer runat="server" ID="menuFooter" />
    </div>
</body>
</html>
<script type="text/javascript">
    function filterPostCate() {
        var selCate = jDoc("sel_Cate");
        window.location = "Index.aspx?cate=" + selCate.options[selCate.selectedIndex].value;
    }

    function PageChanged(index) {
        var params = [];
        params.push("pi=" + index);
        var paramNameList = ["cate", "status", "show_top"];
        var paramValue = "";
        for (var i = 0, len = paramNameList.length; i < len; i++) {
            paramValue = jDoc.queryStringByUrl(paramNameList[i]);
            if (paramValue != null) {
                params.push(paramNameList[i] + "=" + paramValue);
            }
        }
        window.location = "Index.aspx?" + params.join("&");
    }
    function movePostToTrash() {
        var valueList = CheckBox.getValueList("tbl_List", ['chk_TopAll']);
        if (valueList.length == 0) {
            alert("请选择要移至回收站的项目");
            return;
        }
        if (confirm("确定移至回收站吗？")) {
            $.post("Action.ashx", { action: 21, status: 5, ids: valueList.join(',') }, function (jsonData) {
                if (jsonData.success) {
                    alert("操作成功");
                    jDoc.reload();
                } else {
                    alert("操作失败")
                }
            }, "json");
        }
    }
    function movePostToPublish() {
        var valueList = CheckBox.getValueList("tbl_List", ['chk_TopAll']);
        if (valueList.length == 0) {
            alert("请选择要恢复的项目");
            return;
        }
        if (confirm("确定恢复选择的项目吗？")) {
            $.post("Action.ashx", { action: 21, status: 1, ids: valueList.join(',') }, function (jsonData) {
                if (jsonData.success) {
                    alert("操作成功");
                    jDoc.reload();
                } else {
                    alert("操作失败")
                }
            }, "json");
        }
    }
    function hotSettings(id, opName, flag, caller) {
        $.post("Action.ashx", { action: 23, opName: opName, id: id, flag: flag }, function (jsonData) {
            if (jsonData.success) {//应该加上 数量变化
                caller.innerHTML = caller.innerHTML.trim() == "取消" ? "设置" : "取消";
                alert("操作成功");
            } else {
                alert("操作失败")
            }
        }, "json");
    }
</script>
